package com.acme;

import com.acme.bank.Bank;
import com.acme.bank.BankService;
import com.acme.domain.account.Account;
import com.acme.domain.account.CheckingAccount;
import com.acme.domain.account.SavingAccount;
import com.acme.domain.client.Client;
import com.acme.domain.client.Gender;
import com.acme.exceptions.NotEnoughFundsException;

public class BankApplication {
    public static void main(String[] args) {
        Bank bank = new Bank();
        BankService bankService = new BankService();
        Client henry = new Client("Henry", Gender.MALE);
        henry.addAccount(new CheckingAccount(0, 100., 3150.));
        Client scroodge = new Client("Scroodge McDuck", Gender.MALE);
        scroodge.addAccount(new SavingAccount(1, 1000000000000.));
        bankService.addClient(bank, henry);
        bankService.addClient(bank, scroodge);
        printBalance(bank);
        modifyBank(bank);
        printBalance(bank);
    }

    public static void modifyBank(final Bank bank) {
        for (Client client : bank.getClients()) {
            Account account = client.getAccountsList().get(0);
            try{
            account.deposit(-30.);
            }
            catch(IllegalArgumentException e){
                System.out.println(e.getMessage());
            }
            try{
            account.withdraw(50000.);
            }
            catch (IllegalArgumentException e){
                System.out.println(e.getMessage());
            }
            catch(NotEnoughFundsException e){
                System.out.println(e.getMessage());
            }

        }
    }

    public static void printBalance(final Bank bank) {
        for (Client client : bank.getClients()) {
            for (Account account : client.getAccountsList()) {
                System.out.println(client.getSalutation() + ": " + account.getBalance());
            }
        }
        System.out.println();
    }
}
